import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/pages/mall_app/account_safe_modify_phone_sure/state.dart';
import 'package:yp/services/api.dart';

import '../../../helper.dart';
import '../../../router.dart';

class ModifyPhoneSureLogic extends GetxController {
  final ModifyPhonseSureState state = ModifyPhonseSureState();

  @override
  void onInit() {
    super.onInit();
    state.phone = Get.arguments['phone'];
    state.code = Get.arguments['code'];
    state.token = Get.arguments['token'];
    state.oldCode = Get.arguments['oldCode'];
    state.oldToken = Get.arguments['oldToken'];
  }

  /// 确定更换
  void sure() {
    var params = {
      "tenant_num_id": 20,
      "data_sign": 0,
      "message_series": null,
      "request_num_id": null,
      "check_repeat_sign": null,
      "expose_method": null,
      "appkey": null,
      'old_mobile_phone': SpUtil.getString('number'),
      'old_sms_verify_code': state.oldCode,
      'old_sms_verify_token': state.oldToken,
      'old_sms_verify_type': 'memBindCode',
      'new_mobile_phone': state.phone,
      'new_sms_verify_code': state.code,
      'new_sms_verify_token': state.token,
      'new_sms_verify_type': 'memBindCode',
      'usr_num_id': SpUtil.getInt('empeNumId')
    };
    Api.sureModfiyPhone(params).listen((event) {
      if (event["code"] != 0) {
        toast(event["message"]);
        Get.back();
      } else {
        Get.toNamed(RouteConfig.modifyPhoneSuccess, arguments: {
          'phone': state.phone,
          'code': state.code,
          'token': state.token,
        });
      }
    });
  }
}
